package com.derive.education_service.web.admin.controller;

import com.derive.education_service.common.global.ResponseMessage;
import com.derive.education_service.web.admin.service.AdminLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.awt.image.BufferedImage;

@RestController
@Slf4j
@Validated
@CrossOrigin
@RequestMapping("admin")
public class AdminLoginController {

    @Autowired
    private AdminLoginService adminLoginService;

    /**
     * 管理员登录
     * @param request
     * @param account
     * @param password
     * @return
     */
    @PostMapping("adminLogin")
    public ResponseMessage adminLogin(HttpServletRequest request,HttpServletResponse response, @NotBlank(message = "请先输入账号") String account,
                                      @NotBlank(message = "请输入密码") String password,
                                      @NotBlank(message = "验证码不能为空") String code) {
        return adminLoginService.adminLogin(request, response, account, password, code);
    }

    /**
     * 获取验证码
     * @param request
     * @return
     */
    @GetMapping("getVerifyCode")
    public void getVerifyCode(HttpServletRequest request, HttpServletResponse response) {
        adminLoginService.getVerifyCode(request, response);
    }

    /**
     * 退出登录，注销登录
     * @param request
     * @return
     */
    @GetMapping("adminLogout")
    public ResponseMessage adminLogout(HttpServletRequest request) {
        return adminLoginService.adminLogout(request);
    }

    /**
     * 检查用户是否存在
     * @param account
     * @return
     */
    @GetMapping("checkAdmin")
    public ResponseMessage checkAdmin(String account) {
        return adminLoginService.checkAdmin(account);
    }
}
